package dk.aau.walkietalkieui;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.widget.Toast;

public class SettingsActivity extends PreferenceActivity implements
		OnSharedPreferenceChangeListener {

	public static final String KEY_PREF_SYNC_CONN = "prefConnectionStatus";
	public static final String KEY_PREF_SYNC_CONN_TYPE = "prefConnectionType";
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.settings);
		setTitleColor(getResources().getColor(R.color.white));
		// TODO sync with connection status

		// SharedPreference sp = this.getSharedPreferences("settings",
		// MODE_PRIVATE);
		// sp.registerOnSharedPreferenceChangeListener();

	}
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {
		if (key.equals(KEY_PREF_SYNC_CONN_TYPE)) {
			String txt = sharedPreferences.getString(KEY_PREF_SYNC_CONN_TYPE,
					"0");
			Toast.makeText(getApplicationContext(), "Connection type :" + txt,
					Toast.LENGTH_LONG).show();
		}
		// TODO Auto-generated method stub
		// add preference changed actions to do

	}

	@Override
	protected void onResume() {
		super.onResume();
		getPreferenceScreen().getSharedPreferences()
				.registerOnSharedPreferenceChangeListener(this);

	}

	@Override
	protected void onPause() {
		super.onPause();
		getPreferenceScreen().getSharedPreferences()
				.unregisterOnSharedPreferenceChangeListener(this);

	}
}
